if (SERVER) then
	AddCSLuaFile("shared.lua")
	require("datastream")
	local gmsadownloads = file.Read("gmsa/downloads.txt")
	local gmsdownloadst = string.Explode("\n",gmsadownloads)
	for _, v in pairs(gmsdownloadst) do
		resource.AddFile(v)
	end
	local function gmsalog(logdata)
		file.Write("gmsa/log.txt","["..os.date().."] > "..logdata)
	end
	local function findplayerbyname(findname)
		local findname = string.lower(findname)
		for _, v in ipairs(player.GetAll()) do
			if string.find(string.lower(v:Nick()),findname) then
				return v
			end
		end
		return 0
	end
	local function checkisadmin(steamid)
		local gmsadmins = file.Read("gmsa/admins.txt")
		local gmsadminst = string.Explode("\n",gmsadmins)
		for _, v in pairs(gmsadminst) do
			if steamid == v then return 1 end
		end
		return 0
	end
	local function checkissadmin(steamid)
		local gmsaim = file.Read("gmsa/superadmins.txt")
		local gmsaimt = string.Explode("\n",gmsaim)
		for _, v in pairs(gmsaimt) do
			if steamid == v then return 1 end
		end
		return 0
	end
	local function gmsakicks(sender,handler,id,encoded,decoded)
		local gmsaid = findplayerbyname(decoded[1])
		if gmsaid == 0 then return end
		if checkisadmin(sender:SteamID()) == 1 and gmsaid:UserID() != 0 and checkissadmin(gmsaid:SteamID()) == 0 then
			if decoded[2] then game.ConsoleCommand("kickid "..gmsaid:UserID().." "..decoded[2].."\n") else game.ConsoleCommand("kickid "..gmsaid:UserID().."\n") end
			game.ConsoleCommand("say "..sender:Nick().." kicked "..gmsaid:Nick().."\n")
			gmsalog(sender:Nick().." kicked "..gmsaid:Nick().."\n")
		end
	end
	local function gmsabans(sender,handler,id,encoded,decoded)
		local gmsaid = findplayerbyname(decoded[1])
		if gmsaid == 0 then return end
		if checkisadmin(sender:SteamID()) == 1 and gmsaid:UserID() != 0 and checkissadmin(gmsaid:SteamID()) == 0 then
			if decoded[2] then
				game.ConsoleCommand("banid "..decoded[2].." "..gmsaid:UserID().."\n")
				game.ConsoleCommand("kickid "..gmsaid:UserID().." Banned: "..decoded[3].."\n")
				game.ConsoleCommand("say "..sender:Nick().." banned "..gmsaid:Nick().." for "..decoded[2].." minutes\n")
				gmsalog(sender:Nick().." banned "..gmsaid:Nick().." for "..decoded[2].." minutes\n")
			else
				game.ConsoleCommand("banid 0 "..gmsaid:UserID().."\n")
				game.ConsoleCommand("kickid "..gmsaid:UserID().." Banned\n")
				game.ConsoleCommand("say "..sender:Nick().." banned "..gmsaid:Nick().." permanently\n")
				gmsalog(sender:Nick().." banned "..gmsaid:Nick().." permanently\n")
			end
		end
	end
	local function gmsaslays(sender,handler,id,encoded,decoded)
		local gmsaid = findplayerbyname(decoded[1])
		if gmsaid == 0 then return end
		if checkisadmin(sender:SteamID()) == 1 and gmsaid:UserID() != 0 and checkissadmin(gmsaid:SteamID()) == 0 then
			gmsaid:Kill()
			game.ConsoleCommand("say "..sender:Nick().." slayed "..gmsaid:Nick().."\n")
			gmsalog(sender:Nick().." slayed "..gmsaid:Nick().."\n")
		end
	end
	local function gmsaents(sender,handler,id,encoded,decoded)
		if checkisadmin(sender:SteamID()) == 1 then
			name = decoded[1]:lower()
			local enti = ents.Create(name)
			if not enti or not enti:IsValid() then
				return
			end
			local trace = sender:GetEyeTrace()
			local vector = trace.HitPos
			vector.z = vector.z + 20
			enti:SetPos( vector )
			enti:Spawn()
			enti:Activate()
			undo.Create("Spawned Entity")
				undo.AddEntity(enti)
				undo.SetPlayer(sender)
			undo.Finish()
			game.ConsoleCommand("say "..sender:Nick().." spawned a "..decoded[1].."\n")
			gmsalog(sender:Nick().." spawned a "..decoded[1].."\n")
		end
	end
	local function gmsamaps(sender,handler,id,encoded,decoded)
		if checkisadmin(sender:SteamID()) == 1 then
			game.ConsoleCommand("changelevel "..decoded[1].."\n")
			game.ConsoleCommand("say "..sender:Nick().." chaged map to "..decoded[1].."\n")
			gmsalog(sender:Nick().." chaged map to "..decoded[1].."\n")
		end
	end
	local function gmsasay(ply,text,team)
		gmsasayt = string.Explode(" ",text)
		if gmsasayt[1] == "!kick" then
			gmsakicks(ply,0,0,0,{gmsasayt[2],gmsasayt[3]})
		end
		if gmsasayt[1] == "!ban" then
			gmsabans(ply,0,0,0,{gmsasayt[2],gmsasayt[3],gmsasayt[4]})
		end
		if gmsasayt[1] == "!slay" then
			gmsaslays(ply,0,0,0,{gmsasayt[2]})
		end
		if gmsasayt[1] == "!ent" then
			gmsaents(ply,0,0,0,{gmsasayt[2]})
		end
		if gmsasayt[1] == "!map" then
			gmsamaps(ply,0,0,0,{gmsasayt[2]})
		end
	end
	hook.Add( "PlayerSay","gmsasay",gmsasay)
	datastream.Hook("gmsakick",gmsakicks)
	datastream.Hook("gmsaban",gmsabans)
	datastream.Hook("gmsaslay",gmsaslays)
	datastream.Hook("gmsaent",gmsaents)
	datastream.Hook("gmsamap",gmsamaps)
end
if (CLIENT) then
	require("datastream")
	local function gmsakick(player,command,args)
		datastream.StreamToServer("gmsakick",{args[1],args[2]})
	end
	local function gmsaban(player,command,args)
		datastream.StreamToServer("gmsaban",{args[1],args[2],args[3]})
	end
	local function gmsaslay(player,command,args)
		datastream.StreamToServer("gmsaslay",{args[1]})
	end
	local function gmsaent(player,command,args)
		datastream.StreamToServer("gmsaent",{args[1]})
	end
	local function gmsamap(player,command,args)
		datastream.StreamToServer("gmsamap",{args[1]})
	end
	concommand.Add("gmsa_kick",gmsakick)
	concommand.Add("gmsa_ban",gmsaban)
	concommand.Add("gmsa_slay",gmsaslay)
	concommand.Add("gmsa_ent",gmsaent)
	concommand.Add("gmsa_map",gmsamap)
end








